package com.alibaba.citrus.cr.price.ability.functions.entity.price;

import com.epoch.app.crpricecenter.sdo.PriceTypeSDO;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author: qiaojiange
 * @create: 2021/09/15
 * @Description 价格类型实体
 */
@Data
public class PriceTypeEntity {
    /**
     * 维度顺序分隔符
     */
    public static final String DIMENSION_ORDER_SPERATOR = ",";

    private PriceTypeSDO priceTypeSDO;

    public static PriceTypeEntity of(PriceTypeSDO priceTypeSDO) {
        PriceTypeEntity entity = new PriceTypeEntity();
        entity.setPriceTypeSDO(priceTypeSDO);
        return entity;
    }

    /**
     * 获取维度顺序
     *
     * @return
     */
    public List<String> obtainDimensionSequence() {
        if (Objects.isNull(priceTypeSDO)) {
            return new ArrayList<>();
        }
        String[] ids = priceTypeSDO.getDimensionOrder().split(DIMENSION_ORDER_SPERATOR);
        return Arrays.stream(ids).collect(Collectors.toList());
    }

    public Boolean obtainIsNegativeFlag() {
        return this.priceTypeSDO == null ? null : this.priceTypeSDO.getNegativeNumberFlag();
    }

    public Boolean obtainIsManualFlag() {
        return this.priceTypeSDO == null ? null : this.priceTypeSDO.getManualFlag();
    }

    public Boolean obtainIsTitleFlag() {
        return this.priceTypeSDO == null ? null : this.priceTypeSDO.getTitleFlag();
    }

    public String obtainCaculatePattern() {
        return this.priceTypeSDO == null ? null : this.priceTypeSDO.getCalculatePattern();
    }
}
